package com.hk.hibernate;


import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = HConfig.class)
public class HibernateTest {

    @Autowired
    private SessionFactory sessionFactory;



    @Test
    public void test(){
        Session session = null;
        try {
            session = sessionFactory.openSession();
            String version = session.createNativeQuery("SELECT version()").getSingleResult().toString();
            System.out.println(version);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(session != null){
                session.close();
            }
        }

    }


}
